package leetcode;

/**
 * @program: datastructureandalogorithm
 * @description:
 * @author: hmx
 * @create: 2021-12-26 00:36
 **/
public class LeetCode5949 {

    public String abbreviateProduct(int left, int right) {
        long two = 0, five = 0, min = 0, flag = 0, last = 1;
        for (int i = left, j; (j = i) <= right; i++) {
            for (; j % 2 == 0; j /= 2, two++) {
            }
            for (; j % 5 == 0; j /= 5, five++) {
            }
        }
        two = five = min = Math.min(two, five);
        double first = 1;
        for (int i = left; i <= right; i++) {
            for (last *= i; last % 2 == 0 && two-- > 0; last /= 2) {
            }
            for (; last % 5 == 0 && five-- > 0; last /= 5) {
            }
            if (last > 10000000000L) {
                flag = 1;
                last %= 10000000000L;
            }
            for (first *= i; first > 100000; first /= 10) {
            }
        }
        return (flag == 0 ? last : (int) first + "..." + String.format("%05d", last % 100000)) + "e" + min;
    }

}
